import pickle
import pandas as pd

def ReadModels(N_min,N_max,FileInputPkl,FileInpuExcel):
    """
    本代码会将model数据与excel打包生成dict数据类型
    N_min,N_max导入主题模型的文件，根据已生成的LD模型pkl档和excel档具体情况而定
    例如pkl档和excel档有[df_LDA_4,df_LDA_5,df_LDA_6]则N_min=4，N_max=7（range()决定）
    """
    m_data_set = dict()
    for n in range(N_min,N_max):
        with open(FileInputPkl.format(n=n),  'rb') as handle:
            model_data = pickle.load(handle)
        model_data['vocab'] = model_data.pop('term')
        m_data = model_data
        xls_fn = FileInpuExcel.format(n=n)
        with pd.ExcelFile(xls_fn) as xls: 
            all_sheets = xls.sheet_names
        d = dict()
        for sheet in all_sheets:
            d[sheet] = pd.read_excel(xls_fn, sheet_name=sheet, index_col=0)       
        m_data_set[n] = {"model":m_data, "excel":d}   
    return m_data_set


if __name__ == '__main__':
    ReadModels()